import { createPinia } from 'pinia'
import persist from 'pinia-plugin-persistedstate'

const pinia = createPinia()
pinia.use(persist)

export default pinia

// import { userUserStore } from './modules/user'
// export { userUserStore }
//相当于上面那两行接收所有的按需导出
// export * from './modules/user'
import { defineStore } from 'pinia'
import { ref } from 'vue'
// import { userGetInfoServe } from '../../api/user'

//用户模块token setToken removeToke
export const userUserStore = defineStore(
  'userToken',
  () => {
    const token = ref('')
    // 清除token
    const setToken = (newToken) => {
      token.value = newToken
      localStorage.setItem('token',newToken)
    }
    const setRole=(role)=>{
      localStorage.setItem('role',role)
    }
    const getRole=()=>{
      // console.log('进入到仓库获取role');
      return localStorage.getItem('role')
    }

    // 存储用户信息
    const user = ref()
    const getUser =() => {
      // const res = await userGetInfoServe()
      return localStorage.getItem('user')
    }

    // 清除User用户信息
    const setUser = (obj) => {
      user.value = obj
      localStorage.setItem('user',obj)
    }

    return {
      setToken,
      token,
      user,
      getUser,
      setUser,
      setRole,
      getRole
    }
  },
  {
    persist: true
  }
)
